package com.ict.conf;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.ict.util.UserHolderUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author wujinpeng
 * @version 1.0
 * @date 2024/8/25 21:59
 * @description 持久层自动填充拦截器
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        metaObject.setValue("createBy", UserHolderUtils.getUser().getUsername());
        metaObject.setValue("updateBy", UserHolderUtils.getUser().getUsername());
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("updateBy", UserHolderUtils.getUser().getUsername());
        metaObject.setValue("updateTime", LocalDateTime.now());
    }
}
